using UnityEngine;
using System.Collections;

public class Player_Dash_State : State {
		
	private PanningString strPanning;
	private PanningParser strPanningParser;
	private bool Istouch = false;
	private Vector3 BeforeVec3;
	public override void Enter_State(Alive_object _player_script)
	{
		_player_script.animation.Play("idle");
		strPanning = new PanningString();
		strPanningParser = new PanningParser();
		Istouch = false;
		BeforeVec3 = GameManager.getInstance().PlayerControlObject.GetPos();
	}
	public override void Excute_State(Alive_object _player_script)
	{
		if( Input.touchCount != 0 && Istouch.Equals(false) && (_player_script as Player ).player_data_.Player_Dash_Residual_Point > 5 )
		{
			GameManager GM = GameManager.getInstance();
			Transform Dash_Bar = GM.Dash_Bar.transform;
			
			GM.Player_script.player_data_.Player_Dash_Residual_Point -= (Vector3.Distance( BeforeVec3, GM.PlayerControlObject.GetPos()) * GM.Player_script.player_data_.Player_Dash_Cost);
			
			Dash_Bar.transform.localScale = new Vector3(((130*GM.Player_script.player_data_.Player_Dash_Residual_Point) / GM.Player_script.player_data_.Player_Dash_Point_Maximum),20,0);
			BeforeVec3 = GM.PlayerControlObject.GetPos();
			strPanning.AddPanningPosition( GM.PlayerControlObject.GetPos() );
		}
		else
		{
			Istouch = true;
			strPanningParser.SetString(strPanning.GetString);
			Vector3 PanningPos = strPanningParser.GetValue();
			if( strPanningParser.NextPanningString().Equals(true) ){
				GameObject.Instantiate(Resources.Load("test"), PanningPos, Quaternion.identity );
				CollisionManager.getInstance().Request_Attack(((Player)_player_script).player_data_.Player_Dash_Damage , PanningPos);
			}
			else {
				_player_script.animation.Play("attack");
				_player_script.transform.position = PanningPos;
				CollisionManager.getInstance().Request_Attack(((Player)_player_script).player_data_.Player_Dash_Damage , PanningPos);
				
				strPanning.ClearString();
				
				_player_script.fsm.Change_state(_player_script.arr_state_[0],_player_script);
			}	
		}
	}
	public override void Exit_State(Alive_object _player_script)
	{
		_player_script.animation.Stop();
	}
	
}
